package com.duolaibei.business.view.goods.greendao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.duolaibei.business.view.goods.mode.FormatsBean.EmpPointListConvert;
import java.util.List;

import com.duolaibei.business.view.goods.mode.FormatsBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "FORMATS_BEAN".
*/
public class FormatsBeanDao extends AbstractDao<FormatsBean, Long> {

    public static final String TABLENAME = "FORMATS_BEAN";

    /**
     * Properties of entity FormatsBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Title = new Property(1, String.class, "title", false, "TITLE");
        public final static Property IsChoosed = new Property(2, boolean.class, "isChoosed", false, "IS_CHOOSED");
        public final static Property FormatNum = new Property(3, int.class, "formatNum", false, "FORMAT_NUM");
        public final static Property Data = new Property(4, String.class, "data", false, "DATA");
    }

    private final EmpPointListConvert dataConverter = new EmpPointListConvert();

    public FormatsBeanDao(DaoConfig config) {
        super(config);
    }
    
    public FormatsBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"FORMATS_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"TITLE\" TEXT," + // 1: title
                "\"IS_CHOOSED\" INTEGER NOT NULL ," + // 2: isChoosed
                "\"FORMAT_NUM\" INTEGER NOT NULL ," + // 3: formatNum
                "\"DATA\" TEXT);"); // 4: data
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"FORMATS_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, FormatsBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }
        stmt.bindLong(3, entity.getIsChoosed() ? 1L: 0L);
        stmt.bindLong(4, entity.getFormatNum());
 
        List data = entity.getData();
        if (data != null) {
            stmt.bindString(5, dataConverter.convertToDatabaseValue(data));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, FormatsBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }
        stmt.bindLong(3, entity.getIsChoosed() ? 1L: 0L);
        stmt.bindLong(4, entity.getFormatNum());
 
        List data = entity.getData();
        if (data != null) {
            stmt.bindString(5, dataConverter.convertToDatabaseValue(data));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public FormatsBean readEntity(Cursor cursor, int offset) {
        FormatsBean entity = new FormatsBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // title
            cursor.getShort(offset + 2) != 0, // isChoosed
            cursor.getInt(offset + 3), // formatNum
            cursor.isNull(offset + 4) ? null : dataConverter.convertToEntityProperty(cursor.getString(offset + 4)) // data
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, FormatsBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setIsChoosed(cursor.getShort(offset + 2) != 0);
        entity.setFormatNum(cursor.getInt(offset + 3));
        entity.setData(cursor.isNull(offset + 4) ? null : dataConverter.convertToEntityProperty(cursor.getString(offset + 4)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(FormatsBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(FormatsBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(FormatsBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
